<?php
/**
 * @name SamplePlugin
 * @desc Yaf定义了如下的6个Hook,插件之间的执行顺序是先进先Call
 * @see http://www.php.net/manual/en/class.yaf-plugin-abstract.php
 * @author root
 */
//class SamplePlugin extends Yaf_Plugin_Abstract {
class SamplePlugin extends Yaf\Plugin_Abstract {

	public function routerStartup(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
	    echo 1;
	}

	public function routerShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
        echo 2;

    }

	public function dispatchLoopStartup(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
        echo 3;
    }

	public function preDispatch(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
        echo 4;

        $moduleName = $request->getModuleName();
        $viewScriptPath = APP_PATH . '/';
        if($moduleName != 'Index'){
            $viewScriptPath .= 'modules/' . $moduleName . '/views';
            Yaf\Dispatcher::getInstance()->initView($viewScriptPath);
        }else {
//            $viewScriptPath = Yaf\View\Simple::getInstance()->getScriptPath();
//            $viewScriptPath = Yaf\Dispatcher::getInstance()->getApplication()->getScriptPath();
        }
//            ->setScriptPath($viewScriptPath);

    }

	public function postDispatch(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
        echo 5;

    }

	public function dispatchLoopShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
        echo 6;
    }
}
